<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function Cat (name,color){
            this.name = name;
            this.color = color;
            //this.type = "猫";//加入方法，但是有点浪费性能，不建议在构造函数里创建，一个火车不要车厢，没有意义
            //this.eat = function(){
            //    alert("xhc");
            //}
        }
        //constructor在共享属性和方法有点招架不住
        Cat.prototype.type = "猫";//来解决浪费和共享
        Cat.prototype.eat = function(){
            console.log("nh");
        }
        const cat1 = new Cat("yang","123");
        const cat2 = new Cat("yangming","123");
        cat1.type=("狗");
        console.log(cat1.type);
        console.log(cat2.type);
        console.log(Cat.prototype.isPrototypeOf(cat1));//api判断是不是在原型上面的属性
        //判断是实例上的属性还是protype上的属性
        console.log(cat1.hasOwnProperty('type'));
        console.log(cat1.hasOwnProperty('name'));
        console.log("name" in cat1);
        for(var x in Cat){
            console.log(x);
        }
    </script>
</body>
</html>